package 线程的学习;

import java.util.Date;

public class TestBlocked {
    public static void main(String[] args) {

        MyThread2 thread=new MyThread2();
        thread.start();
        try{
            System.out.println("我是线程："+Thread.currentThread().getName());
//            主线程休眠十秒
            thread.sleep(1000);
        }catch(InterruptedException e){

        }
        thread.interrupt();
    }
}
class MyThread2 extends Thread{
    boolean flag=true;

    @Override
    public void run() {
        while(flag){
            System.out.println("...."+new Date()+".... 我是线程"+Thread.currentThread().getName());
            try{
                sleep(100);
            }catch (InterruptedException e){
                return;//接收到终端请求，立即结束run()方法
            }
        }
    }
}